#include "Field.h"

void Field::add_item(std::string val) {
    if (this->type == 0) {
        this->records_int.push_back(std::stoi(val));
    } else if (this->type == 1) {
        this->records_float.push_back(std::stof(val));
    } else {
        this->records_string.push_back(val);
    }
}

void Field::delete_item(int id) {
    if (this->type == 0) {
        this->records_int.erase(this->records_int.begin() + id);
    } else if (this->type == 1) {
        this->records_float.erase(this->records_float.begin() + id);
    } else {
        this->records_string.erase(this->records_string.begin() + id);
    }
}

bool Field::match(int id, char op, std::string val) {
    // op = '>'
    // val = "60"

    if (this->type == 0) {
        if (op == '>' && this->records_int[id] > std::stoi(val)) return true;
        else if (op == '<' && this->records_int[id] < std::stoi(val)) return true;
        else if (op == '=' && this->records_int[id] == std::stoi(val)) return true;
    } else if (this->type == 1) {
        if (op == '>' && this->records_float[id] > std::stof(val)) return true;
        else if (op == '<' && this->records_float[id] < std::stof(val)) return true;
        else if (op == '=' && this->records_float[id] == std::stof(val)) return true;
    } else {
        if (val == this->records_string[id]) return true;
    }

    return false;
}

void Field::print_item(int id) {
    if (this->type == 0) {
        std::cout << this->records_int[id] << " ";
    } else if (this->type == 1) {
        std::cout << this->records_float[id] << " ";
    } else {
        std::cout << this->records_string[id] << " ";
    }
}
